package com.vip.xchat.controller;

import com.vip.file.constant.UrlConstant;
import com.vip.file.model.response.Result;
import com.vip.xchat.model.Xchat;
import com.vip.xchat.model.Xsession;
import com.vip.xchat.model.Xuser;
import com.vip.xchat.service.IUserService;
import com.vip.xchat.service.IXChatService;
import com.vip.xchat.service.IXSessionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping(UrlConstant.API + "/xchat")
public class XChatController {

    @Autowired
    private IXChatService ixChatService;

    @Autowired
    private IUserService iUserService;

    @Autowired
    private IXSessionService ixSessionService;

    @PostMapping("/adduser")
    public Result<Object> addXUser(Xuser xuser) {
        return iUserService.addUser(xuser);
    }

    @GetMapping("/getuserlist")
    public Result<Object> getuserlist(Xuser xuser) {
        return iUserService.getuserlist(xuser);
    }

    @PostMapping("/checkuser")
    public Result<Object> checkuser(Xuser xuser) {
        return iUserService.checkuser(xuser);
    }

    @PostMapping("/addsession")
    public Result<Object> addSeesion(Xsession xsession) {
        return ixSessionService.addSeesion(xsession);
    }

    @GetMapping("/getsessionlist")
    public Result<Object> getSessionList(Xsession xsession) {
        return ixSessionService.getSessionList(xsession);
    }

    @PostMapping("/send")
    public Result<Object> sendXChat(Xchat xChat) {
        return ixChatService.sendXChat(xChat);
    }

    @GetMapping("/list")
    public Result<Object> getXChatList(@RequestParam(required = false) Integer pageNo,
                                       @RequestParam(required = false) Integer pageSize,
                                       @RequestParam String userId,
                                       @RequestParam String sessionId) {
        return ixChatService.selectXChatList(pageNo, pageSize, userId,sessionId);
    }

}
